/***************************************************************************
 *   Copyright (C) 2010 by Oleg Goncharov  *
 *   $EMAIL$                           *                          
 *                                                                         *
 *   This file is part of ChessVision.                                     *
 *                                                                         *
 *   ChessVision is free software; you can redistribute it and/or modify   *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef CHTRANSDETECTOR_H
#define CHTRANSDETECTOR_H

#include <cchessdetector.h>

namespace Chess {

/**
	Определяет положение доски при помощи поиска точек, соответствующим параллельным и равноудаленным прямым, на преобразовании Хоупфа границ, выделленных алгоритсмом Canny.
	
	@author Goncharov Oleg <goncharovoi@yandex.ru>
*/
class CHTransDetector : public CChessDetector
{
protected:
	float rho_step, teta_step;
	float min_board_size;
	float tweak_rho, tweak_teta;
	int therehold1, therehold2;
public:
    CHTransDetector();
	~CHTransDetector();
	
	void SetSteps(float _rho_step = 0.7f, float _teta_step = 0.03f) { 
		rho_step = _rho_step; teta_step = _teta_step; 
	}
	void SetCannyThereholds(int _therehold1 = 30, int _therehold2 = 90) {
		therehold1 = _therehold1; therehold2 = _therehold2;
	}
	void SetMinBoardSize(float r_size = 0.5f) {
		min_board_size = r_size;
	}
	void SetTweak(float tweak_angle = 0.03f, float _tweak_rho = 0.3f) {
		tweak_rho = _tweak_rho; tweak_teta = tweak_angle;
	}
	bool DetectChessboard(IplImage * src, CBoardCells& cells);
protected:
	Line2f RefineLine(const cv::Mat& ht, const cv::Point& pt, const cv::Size& rect_size);
};

}

#endif
